class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        unordered_map<char, int> map1;
        unordered_map<char, int> map2;
        vector<int> v;
        for (auto& e : p)
        {
            map1[e]++;
        }
        int right = 0;
        int left = 0;
        while ((right - left) < p.size())
        {
            map2[s[right]]++;
            right++;
        }
        while (right < s.size())
        {
            if (map1 == map2)
            {
                v.push_back(left);
            }
            map2[s[left]]--;

            if (map2[s[left]] == 0)
                map2.erase(s[left]);
            left++;
            map2[s[right]]++;
            right++;
        }
        if (map1 == map2)
        {
            v.push_back(left);
        }
        return v;
    }

};